package adminServlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;

import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import adminejb.CountryBeanLocal;
import repositories.CountryRepository;
import specifications.CountrySpecification;
import entities.Country;

import java.util.Map;

/**
 * Servlet implementation class editCountry
 */
@WebServlet("/getParamsToEditCountry")
public class getParamsToEditCountry extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public getParamsToEditCountry() {
        super();
        // TODO Auto-generated constructor stub
    }
    
    @EJB
    CountryBeanLocal countryBean;
    
    protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    	
    	Country foundCountry = countryBean.findCountry("countryName", new String(request.getParameter("countryname").getBytes("ISO-8859-1"),"UTF-8"));
    	
    	Map<String, String> map = new HashMap<String, String>();
    	map.put("action", "edit");
    	map.put("id", String.valueOf(foundCountry.getId()));
    	map.put("countryname", foundCountry.getCountryName());
    	map.put("countrycode", String.valueOf(foundCountry.getCountryCode()));
    	
    	request.setAttribute("map", map);
    	getServletContext().getRequestDispatcher("/admin/EditCountry.jsp").forward(request, response);
    	
    }
   
    
    
	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		processRequest(request, response);	
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		processRequest(request, response);	
	}

}
